<template>
	
	
	<!-- 开屏logo页面 -->
	<view class="loading">
		<image src="/static/home/logo.png" mode="aspectFill"></image>
		
		
		<!-- 隐私协议 -->
		<!-- <uni-popup ref="popup">
			<view class="popupWrap">
				<view class="popupTxt">
					 在你使用【{{ plat_name }}】 服务之前，请仔细阅读<text class="blueColor" @click="handleOpenPrivacyContract"> 《{{ plat_name }}隐私保护指引》</text>。如你同意《{{ plat_name }}隐私保护指引》，请点击“同意”开始使用【{{ plat_name }}】。
				</view>
				<view class="popupBot">
					<button id="disagree-btn" type="default" @click="handleDisagree">拒绝</button>
					<button id="agree-btn" type="primary" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
				</view>
			</view>
		</uni-popup> -->
	
	</view>
</template>

<script>
	import api from '@/api/home.js'

	export default {
		components: {
		
		},
		data() {
			return {
				longitude: '',
				latitude: '',
				needAuthorization:true,
				plat_name:'加油保小程序'
			};
		},
		onLoad(options) {
			// uni.getPrivacySetting({
			// 	success: res => {
			// 	//如果需要授权的话 显示弹窗
			// 	 this.needAuthorization = res.needAuthorization
			// 	 //console.log(res.needAuthorization,'needAuthorization')
			// 	  if(this.needAuthorization){
			// 			 this.$refs.popup.open('center') ;
						
			// 	  }else{
			// 		 this.getLoacl();
			// 	  }
			// 	},
			// 	fail: () => {},
			// 	complete: () => {},
			// })
			
			if (options && options.invite) {
				uni.setStorageSync('userDistCode', options.invite);
				if (!uni.getStorageSync('userinfo').token) {
					console.log("未登录222");
				} else {
					this.getInsBinding()
				}
			}
			let launchOpt = uni.getLaunchOptionsSync();
			if (launchOpt.query && launchOpt.query.invite != null) {
				uni.setStorageSync('userDistCode', launchOpt.query.invite);
				console.log(launchOpt.query.invite, "首页接受的邀请码");
				// if(launchOpt.query.invite){
				if (!uni.getStorageSync('userinfo').token) {
					console.log("未登录222");
				} else {
					this.getInsBinding()
				}
			}
		},
		onShow() {
			this.longitude = ''
			this.latitude = ''
			// #ifdef MP-ALIPAY
			// 支付宝小程序关闭页面下拉(默认开启下拉)
			my.setCanPullDown({
				canPullDown: false
			});
			// #endif
			this.getLoacl();
		},
		mounted() {
			// #ifdef MP-ALIPAY
			// 支付宝小程序关闭页面下拉(默认开启下拉)
			my.setCanPullDown({
				canPullDown: false
			});
			// #endif

			// this.getLoacl();
		},
		methods: {
			// handleDisagree(e) {
			// 		  this.$refs.popup.close();
			// 		 setTimeout(() => {
			// 			uni.reLaunch({
			// 				url: "/pages/home/index"
			// 			});
			// 		 }, 1000);
			// 	},
			// handleAgreePrivacyAuthorization(res) {
			// 				  // 用户同意隐私协议事件回调
			// 				  // 用户点击了同意，之后所有已声明过的隐私接口和组件都可以调用了
			// 				  this.$refs.popup.close()
			// 				  this.getLoacl();
			// 	},
		 //    handleOpenPrivacyContract(){
			// 				// 打开隐私协议页面
			// 		wx.openPrivacyContract({
			// 		  success: () => {
						  
			// 		  }, // 打开成功
			// 		  fail: (res) => {
			// 			   this.$refs.popup.open('center') ;
			// 			   uni.showModal({
			// 			   	title: '隐私协议打开失败',
			// 			   	content: `隐私协议打开失败`,
			// 			   	//showCancel: false,
			// 			   	confirmText: '刷新',
			// 			   	cancelText: '取消',
			// 			   	success: (res) => {
			// 			   		console.log(res,1111111111111);
			// 			   		if (res.confirm) {
			// 			   			this.getLoacl();
			// 			   		}else{
			// 			   			uni.reLaunch({
			// 			   					url: "/pages/home/index"
			// 			   				});
			// 			   		}
			// 			   	}
			// 			   });
			// 			   setTimeout(() => {
			// 			   						uni.reLaunch({
			// 			   							url: "/pages/home/index"
			// 			   						});
			// 			   }, 1000);
			// 		  }, // 打开失败
			// 		  complete: (res) => {
			// 			  console.log(res,"openPrivacyContract complete");
			// 		  }
			// 		})
			// },
			getInsBinding() {
				api.getInsBinding({
					token: uni.getStorageSync('userinfo').token,
					invite: uni.getStorageSync('userDistCode')
				}).then(res => {
					if (res.code == 1) {
						this.getUserInfo();
					}
				})
			},
			getLoacl() {
				let that = this;
				uni.getLocation({
					// #ifndef MP-ALIPAY
					type: 'gcj02',
					// #endif
					success: (result) => {
						if (result.errMsg == 'getLocation:ok') {
							let address = {
								longitude: result.longitude,
								latitude: result.latitude
							};
							this.longitude = result.longitude;
							this.latitude = result.latitude
						    uni.setStorageSync('address', address);
							// console.log(address,"获取定位");
							// 跳转首页，携带经纬度
							setTimeout(() => {
								uni.reLaunch({
									url: "/pages/home/index?longitude=" + this.longitude +
										"&latitude=" +
										this.latitude
								});
							}, 1000);
						};
					},
					fail: (err) => {
						// 定位失败，跳转首页,不携带参数
						// #ifndef MP-ALIPAY
						uni.showModal({
							title: '未开启手机GPS',
							content: `请打开手机GPS定位权限（屏幕下拉中的位置权限）`,
							//showCancel: false,
							confirmText: '刷新',
							cancelText: '取消',
							success: (res) => {
								if (res.confirm) {
									this.getLoacl();
								}else{
									uni.reLaunch({
											url: "/pages/home/index"
										});
								}
							}
						});
						// #endif
						// #ifdef MP-ALIPAY
						setTimeout(() => {
							uni.reLaunch({
								url: "/pages/home/index"
							});
						}, 1000);
						// #endif
					}
				})		
								
				
			}
		},
	}
</script>
<style lang='scss' scoped>
	.loading {
		position: relative;
		height: 100vh;
		background-color: #fff;

		image {
			width: 160rpx;
			height: 160rpx;
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
			border-radius: 10rpx;
		}
	}
	
	/* .popupWrap{
			  width: 540rpx;
	 	box-sizing: border-box;
	 	padding:42rpx;
	 	background:white;
	 	border-radius: 30rpx;
			z-index: 999999;
			.blueColor{
				color: rgba(39, 152, 240, 1);
			}
			.popupTxt{
				line-height: 48rpx;
			}
	 	.popupBot{
	 		display: flex;
				justify-content: space-around;
				align-items: center;
				margin-top: 30rpx;
	 	}
	 } */
</style>
